<?php

namespace app\process;
use support\Cache;
class MqttClient
{
    public $mqtt = null;
    public function onWorkerStart()
    {
        $mqtt = new \Workerman\Mqtt\Client('mqtt://mqtt.tinycool.cn:1883', array(
            'debug' => true,
            "username"=>"admin", "password"=>"wxk668899"
        ));
        $mqtt->onConnect = function($mqtt) {
            // $mqtt->subscribe('wxk/send');//订阅一个消息 然后下面才能接收到
            // $mqtt->publish('workerman1', 'hello workerman mqtt12222');//向主题发送内容
            // $mqtt->subscribe('workerman2');
            // $mqtt->subscribe('workerman3');
            // $mqtt->subscribe('workerman4');
        };
        // $mqtt->onMessage = function($topic, $content){
        //     $content = json_decode($content,true);
        //     // var
        //     //处理微小库插座
        //     if(isset($content['Cmd'])){
        //         if($content['Cmd']=='pushSwitchStatus'){
        //             Cache::set('pushSwitchStatus'.$content['DeviceName'],$content);
        //         }
        //     }
        //     // echo "topic:$topic content1111:$content\n";
        // };
        
        $mqtt->connect();


    }
}